package com.example.warehouse.controller;

import com.example.warehouse.dto.StockRequestDTO;
import com.example.warehouse.entity.InventoryLog;
import com.example.warehouse.service.InventoryLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/inventory-log")
public class InventoryLogController {
    @Autowired
    private InventoryLogService inventoryLogService ;
    @PostMapping("/stock-in")
    public String stockIn(@RequestParam Long productId, @RequestParam int quantity, @RequestParam String operator){
        inventoryLogService.stockIn(productId,quantity,operator);
        return "入库成功";
    }
    @PostMapping("stock-out")
    public String stockOut(@RequestParam Long productId, @RequestParam int quantity, @RequestParam String operator ){
        inventoryLogService.stockOut(productId, quantity, operator);
        return "出库成功";
    }


    @PostMapping("/adjust-stock")
    public String adjustStock(@RequestBody InventoryLog inventoryLog) {
        try {
            inventoryLogService.adjustStock(inventoryLog.getProductId(), inventoryLog.getQuantity(), inventoryLog.getOperator());
            return "库存调整成功";
        } catch (Exception e) {
            return "库存调整失败: " + e.getMessage();
        }
    }


    // 批量入库
    @PostMapping("/batch-stock-in")
    public String batchStockIn(@RequestBody List<StockRequestDTO> stockInRequests) {
        inventoryLogService.batchStockIn(stockInRequests);
        return "批量入库成功";
    }

    // 批量出库
    @PostMapping("/batch-stock-out")
    public String batchStockOut(@RequestBody List<StockRequestDTO> stockOutRequests) {
        inventoryLogService.batchStockOut(stockOutRequests);
        return "批量出库成功";
    }


}
